<?php
/**
 * User: 魔十七
 * Date: 2020/11/6
 * Time: 10:16
 */

namespace Samecity\Controller;

use think\Controller;
class AllController extends Controller
{
    public function getlist(){
        $back=array(
            'code'=>0,
            'msg'=>'加载成功',
            'data'=>array()
        );
        $post=$_POST;
        $type=$post['type'];
        $city=$post['city'];
        $order=isset($post['order']) ? $post['order'] : 0 ;
        if($type){
            if($city){
                $map['city']=$city;
                $list=[];
                //判断获取类型
                if($type==1){//招聘

                    $list=M('recruit')->field("samecity_recruit.*,FROM_UNIXTIME(samecity_recruit.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_recruit.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_recruit.id desc');
                    }else{
                        $list=$list->order('samecity_recruit.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==2){//本地服务samecity_local
                    $list=M('local')->field("samecity_local.*,FROM_UNIXTIME(samecity_local.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_local.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_local.id desc');
                    }else{
                        $list=$list->order('samecity_local.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==3){//房屋samecity_house

                    $list=M('house')->field("samecity_house.*,FROM_UNIXTIME(samecity_house.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_house.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_house.id desc');
                    }else{
                        $list=$list->order('samecity_house.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==4){//生意转让
                    $list=M('business_transfer')->field("samecity_business_transfer.*,FROM_UNIXTIME(samecity_business_transfer.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_business_transfer.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_business_transfer.id desc');
                    }else{
                        $list=$list->order('samecity_business_transfer.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==5){//汽车交易samecity_car_trading
                    $list=M('car_trading')->field("samecity_car_trading.*,FROM_UNIXTIME(samecity_car_trading.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_car_trading.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_car_trading.id desc');
                    }else{
                        $list=$list->order('samecity_car_trading.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==6){//二手物品
                    $list=M('car_trading')->field("samecity_car_trading.*,FROM_UNIXTIME(samecity_car_trading.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_car_trading.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_car_trading.id desc');
                    }else{
                        $list=$list->order('samecity_car_trading.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==7){//装修decoration_customization
                    $list=M('decoration_customization')->field("samecity_decoration_customization.*,FROM_UNIXTIME(samecity_decoration_customization.add_time,'%Y年%m月%d日') as add_date,samecity_user.avatar,samecity_user.nickname")
                        ->join('samecity_user  ON samecity_decoration_customization.uid = samecity_user.id')
                        ->where($map);
                    if($order){
                        $list=$list->order('samecity_decoration_customization.id desc');
                    }else{
                        $list=$list->order('samecity_decoration_customization.views desc');
                    }
                    $list=$list->select();

                    foreach ($list as $k=>$v){
                        $v['images']=explode(',',$v['images']);
                        $list[$k]=$v;
                    }
                }elseif($type==8){
                    $list=M('')->where()->select();
                }elseif($type==9){
                    $list=M('')->where()->select();
                }
                $back['data']=$list;
            }else{
                $back['msg']='city异常';
                $back['code']=1;
            }
        }else{
            $back['code']=1;
            $back['msg']='type异常';
        }
        $this->ajaxReturn($back);
    }
}